<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>创建报价单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <c:set value="<%=ResourcesUtil.getConfig(\"audit_uncommit\") %>" var="audit_00"/>
    <c:set value="<%=ResourcesUtil.getConfig(\"reserver_meterial_no\") %>" var="audit_30"/>
    <!-- 采购类别：预警采购 -->
    <c:set value="<%=ResourcesUtil.getConfig(\"purchaseType_30\") %>" var="purchaseType30"/>
    <script>
    $(function(){
            $(".tabBox ul li").each(function(){
                var index=$(this).index();

                $(".tabBox ul li").eq(0).addClass("active");

                $(this).click(function(){

                    //alert(index);

                    $(this).addClass("active").siblings().removeClass("active");

                    $(".tabBoxSm > .tabSm").eq(index).stop(true).show().siblings().stop(true).hide();
					
					var tableW = $(".tabBoxSm > .tabSm").eq(index).find('.tableHead').width();
					var tabodyH = $(".tabBoxSm > .tabSm").eq(index).find('.tableBody').height();
					var tableScrollH = $(".tabBoxSm > .tabSm").eq(index).find('.tableScroll').height();
					if(tabodyH>tableScrollH){
						$(".tabBoxSm > .tabSm").eq(index).find('.tableScroll').css('width',tableW + 18 + 'px')
					}else{
						$(".tabBoxSm > .tabSm").eq(index).find('.tableScroll').css('width','inherit')
					}

                })

            })

        })
        
        
    /*  提交  */
    function commitContract(){
    	if (confirm("<spring:message code="purchaseContrac_edit_areYouSureCommit"/>")) {
    		var id = $("#id").val();
    		var param = {"id":id};
    		$.post("${ctx}/purchase/contract/commit",param,function(result){
    			/* 弹出提示框,刷新父页面,关闭当前页面 */
    			tipParent(result.message);
    			 window.parent.frames[0].searchListForm();
    			closeWin();
    		},'json');
    	}
    }
    /* 删除  */
    function deleteContract(){
    	if (confirm("<spring:message code="purchaseContrac_edit_areYouSureDelete"/>")) {
    		var id = $("#id").val();
    		var param = {"id":id};
    		$.post("${ctx}/purchase/contract/delete",param,function(result){
    			/* 弹出提示框,刷新父页面,关闭当前页面 */
    			tipParent(result.message);
    			 window.parent.frames[0].searchListForm();
    			closeWin();
    		},'json');
    	}
    }
    function excelExport() {
    	$("#inputForm").submit();
    }
    /* 审核通过后调用， 如果为预警采购 更新物料预警状态   */
    function updateAlertStatus() {
    	var purchaseType = $("#purchaseType").val();
    	var ognizationIDB = $("#ognizationIDB").val();
    	var purchaseType30 = "${purchaseType30}";
		if (purchaseType == purchaseType30) {
			var materialIDStr = "";
			var materialIdObj = document.getElementsByName("materialID");
			if (materialIdObj != null && materialIdObj.length > 0) {
				for (var i = 0; i < materialIdObj.length; i++) {
					materialIDStr = materialIDStr + materialIdObj[i].value + ",";
				}
			}
			$.post("${ctx}/purchase/contract/updateAlertStatus?materialIDStr="+materialIDStr+"&ognizationIDB="+ognizationIDB,"",function(result){
				closeWin();
			},'json');
		}
	}
    </script>
    <style type="text/css">
    .w-640{
	width:640px;
	}
	.w-65{
	width:65px;
	}
    </style>
</head>
<body>
<!-- 查看头部 -->   
<div class="layerHeader clearfix">
	<p class="headerTitle"><spring:message code="purchaseContract_edit_viewContract"/></p>
    <div class="headerButton clearfix">
    <button type="button" onclick="excelExport();"><spring:message code="purchase_excel_download"/></button>
    <c:if test="${purchaseContract.deleteFlag==0}">
    	<c:if test="${purchaseContract.contractAuditStatus==audit_00}">
   	 	<!-- 提交按钮 -->
   	 	<shiro:hasPermission name="purchase:contract:edit">
    		<button type="button" onclick="commitContract();"><spring:message code="purchaseContract_edit_commit"/></button>
    	</shiro:hasPermission>
    	</c:if>
    	<c:if test="${purchaseContract.contractAuditStatus!=audit_00}">
    	<!-- 审核按钮 -->
    	<shiro:hasPermission name="purchase:contract:audit">
    		<button type="button" onclick="popup('800px','519px','${ctx}/purchase/contract/audit?id=${purchaseContract.id }')"><spring:message code="purchaseContract_edit_audit"/></button>
    	</shiro:hasPermission>
    	</c:if>
    	<c:if test="${purchaseContract.contractAuditStatus==audit_00||purchaseContract.contractAuditStatus==audit_30}">
    	<shiro:hasPermission name="purchase:contract:edit">
	    	<!-- 删除按钮 -->
	        <button type="button" onclick="deleteContract();"><spring:message code="purchaseContract_edit_delete"/></button>
	        <!-- 编辑按钮 -->
	        <button type="button" onclick="window.location.href='${ctx}/purchase/contract/editContract?id=${purchaseContract.id}'"><spring:message code="purchaseContract_edit_edit"/></button>
    	</shiro:hasPermission>
    	</c:if>
    </c:if>
        <button type="button" onclick="closeWin()"><spring:message code="purchaseContract_edit_cancle"/></button>
    </div>
</div>
<form id="inputForm" ACTION="${ctx}/purchase/contract/exportFile" method="post">
<input type="hidden" name="ognizationNameA" value="${purchaseContract.ognizationNameA }"/>
<input type="hidden" name="ognizationNameB" value="${purchaseContract.ognizationNameB }"/>
<input type="hidden" name="ognizationAddressA" value="${purchaseContract.ognizationAddressA }"/>
<input type="hidden" name="ognizationAddressB" value="${purchaseContract.ognizationAddressB }"/>
<input type="hidden" name="legalPersonA" value="${purchaseContract.legalPersonA }"/>
<input type="hidden" name="contactPersonA" value="${purchaseContract.contactPersonA }"/>
<input type="hidden" name="legalPersonB" value="${purchaseContract.legalPersonB }"/>
<input type="hidden" name="contactPersonB" value="${purchaseContract.contactPersonB }"/>
<input type="hidden" name="contactPhoneA" value="${purchaseContract.contactPhoneA }"/>
<input type="hidden" name="contactFaxA" value="${purchaseContract.contactFaxA }"/>
<input type="hidden" name="contactPhoneB" value="${purchaseContract.contactPhoneB }"/>
<input type="hidden" name="contactFaxB" value="${purchaseContract.contactFaxB }"/>
<input type="hidden" name="contactEmailA" value="${purchaseContract.contactEmailA }"/>
<input type="hidden" name="contactEmailB" value="${purchaseContract.contactEmailB }"/>
<input type="hidden" name="paymentWay" value="${fns:getDictName(purchaseContract.paymentWay) }"/>
<input type="hidden" name="contractStatus" value="${fns:getDictName(purchaseContract.contractStatus) }"/>
<input type="hidden" name="purchaseType" value="${fns:getDictName(purchaseContract.purchaseType) }"/>
<input type="hidden" name="contractMaterialQuantity" value="${purchaseContract.contractMaterialQuantity }"/>
<input type="hidden" name="contractAmount" value="${purchaseContract.contractAmount }"/>
<input type="hidden" name="specialExplain" value="${purchaseContract.specialExplain }"/>
<input type="hidden" name="contractDateTime" value="<fmt:formatDate value="${purchaseContract.contractDateTime }" pattern="yyyy-MM-dd" />"/>
<input type="hidden" name="contractClause" value="${purchaseContract.contractClause }"/>
<input type="hidden" name="createBy.firstName" value="${purchaseContract.createBy.firstName }"/>
<input type="hidden" name="createDate" value="<fmt:formatDate value="${purchaseContract.createDate }" pattern="yyyy-MM-dd" />"/>
<input type="hidden" name="contractMaterialNO" value="${purchaseContract.contractMaterialNO }"/>
<input type="hidden" name="clauseType" value="${purchaseContract.clauseType }"/>
<input type="hidden" name="bankName" value="${purchaseContract.bankName }"/>
<input type="hidden" name="bankAccountNo" value="${purchaseContract.bankAccountNo }"/>
<div class="tabBox">
    <ul class="clearfix">
     	<li class="active" style="width: 100px"><spring:message code="purchaseContract_edit_contractMessage"/></li>
        <li style="width: 110px"><spring:message code="purchaseContract_edit_materialList"/></li>
    </ul>
    
</div>
<div  class="tabBoxSm">
    <div class="tabSm smOrderBox showHtml">
    <c:set value="PURCHASE_TYPE-20" var="typeOfOrder"/>
	<c:set value="PURCHASE_TYPE-10" var="typeOfMtm"/>
    <input type="hidden" id="id" name="id" value="${purchaseContract.id }"/>
        <div class="items clearfix">
            <div class="col-50 clearfix haveToBox">
                <p class="tit"><spring:message code="purchaseContract_edit_companyA"/></p>
                <input value="${purchaseContract.ognizationNameA }" style="width: 315px">
                <p class="haveTo">*</p>
            </div>
            <div class="col-50 clearfix">
                <p class="tit"><spring:message code="purchaseContract_edit_companyB"/></p>
                <input value="${purchaseContract.ognizationNameB }" style="width: 315px">
                <input type="hidden" id="ognizationIDB" value="${purchaseContract.ognizationIDB }"/>
            </div>
        </div>
        <div class="items clearfix">
            <div class="col-50 clearfix">
                <p class="tit"><spring:message code="purchaseContract_edit_address"/></p>
                <input value="${purchaseContract.ognizationAddressA }" style="width: 315px">
            </div>
            <div class="col-50 clearfix">
                <p class="tit"><spring:message code="purchaseContract_edit_address"/></p>
                <input value="${purchaseContract.ognizationAddressB }" style="width: 315px">
            </div>
        </div>
        <div class="items clearfix">
            <div class="col-50 clearfix">
          		<div class="left clearfix">
                	<p class="tit"><spring:message code="purchaseContract_edit_legalPerson"/></p>
                	<input value="${purchaseContract.legalPersonA }" style="width: 110px">
            	</div>
            	<div class="right clearfix" style="margin-right: 100px;">
                	<p class="tit"><spring:message code="purchaseContract_edit_contactPerson"/></p>
                	<input value="${purchaseContract.contactPersonA }" style="width: 110px">
            	</div>
            </div>
            <div class="col-50 clearfix">
            	<div class="left clearfix">
                	<p class="tit"><spring:message code="purchaseContract_edit_legalPerson"/></p>
                	<input value="${purchaseContract.legalPersonB }" style="width: 110px">
            	</div>
            	<div class="right clearfix" style="margin-right: 100px;">
                	<p class="tit"><spring:message code="purchaseContract_edit_contactPerson"/></p>
               		<input value="${purchaseContract.contactPersonB }" style="width: 110px">
            	</div>
            </div>
        </div>
        <div class="items clearfix">
            <div class="col-50 clearfix">
            	<div class="left clearfix">
                	<p class="tit"><spring:message code="purchaseContract_edit_contactPhone"/></p>
                	<input  value="${purchaseContract.contactPhoneA }" style="width: 110px">
            	</div>
            	<div class="right clearfix" style="margin-right: 100px;">
                	<p class="tit"><spring:message code="purchaseContract_edit_contactFax"/></p>
               		<input  value="${purchaseContract.contactFaxA }" style="width: 110px">
            	</div>
            </div>
            <div class="col-50 clearfix">
            	<div class="left clearfix">
                	<p class="tit"><spring:message code="purchaseContract_edit_contactPhone"/></p>
                	<input  value="${purchaseContract.contactPhoneB }" style="width: 110px">
            	</div>
            	<div class="right clearfix" style="margin-right: 100px;">
                	<p class="tit"><spring:message code="purchaseContract_edit_contactFax"/></p>
               		<input  value="${purchaseContract.contactFaxB }" style="width: 110px">
            	</div>
            </div>
        </div>
        <div class="items clearfix">
            <div class="col-50 clearfix">
                <p class="tit"><spring:message code="purchaseContract_edit_contactEmail"/></p>
                <input value="${purchaseContract.contactEmailA }" style="width: 315px">
            </div>
            <div class="col-50 clearfix">
                <p class="tit"><spring:message code="purchaseContract_edit_contactEmail"/></p>
                <input value="${purchaseContract.contactEmailB }" style="width: 315px">
            </div>
        </div>
        <div class=" clearfix" >
        	<p class="title" style="margin-top: 2px"><spring:message code="purchaseContract_edit_contractBasicMessage"/></p>
        </div>
        <div class="clearfix">
            	<div class="items clearfix">        	
                    <div class="col-33 clearfix haveToBox">
                    <!-- 付款方式  -->
                        <p class="tit"><spring:message code="purchaseContract_edit_paymentWay"/></p>
                        <input  value="${fns:getDictName(purchaseContract.paymentWay) }">
                        <p class="haveTo">*</p>
                    </div>
                    <div class="col-33 clearfix haveToBox">
                    <!-- 合同状态  -->
                        <p class="tit"><spring:message code="purchaseContract_edit_contractStatus"/></p>
                        <input   value="${fns:getDictName(purchaseContract.contractStatus) }">
						<p class="haveTo">*</p>
                    </div>
                    <div class="col-33 clearfix haveToBox">
                    <!-- 采购类别  -->
                        <p class="tit"><spring:message code="purchaseContract_edit_purchaseType"/></p>
                        <label>${fns:getDictName(purchaseContract.purchaseType) }</label>
                        <input type="hidden" id="purchaseType" value="${purchaseContract.purchaseType }"/>
                    </div>
                </div>
            <div class="left w-640">
                <div class="items clearfix">        	
                    <div class="col-50 clearfix haveToBox">
                    <!-- 订料总数 -->
                        <p class="tit"><spring:message code="purchaseContract_edit_contractQuantity"/></p>
                        <input   value="${purchaseContract.contractMaterialQuantity }">
                        <p class="haveTo">*</p>
                    </div>
                    <div class="col-50 clearfix haveToBox">
                    <!-- 订单金额  -->
                        <p class="tit"><spring:message code="purchaseContract_edit_contractAmount"/></p>
                        <input   value="${purchaseContract.contractAmount }">
                        <p class="haveTo">*</p>
                    </div>
                </div>
                <div class="items clearfix">        	
                    <div class="col-50 clearfix haveToBox">
                    <!-- 签订日期  -->
                        <p class="tit"><spring:message code="purchaseContract_edit_contractDateTime"/></p>
                        <input  type="text"  value="<fmt:formatDate value="${purchaseContract.contractDateTime }" pattern="yyyy-MM-dd" />">
                        <p class="haveTo">*</p>
                    </div>
                    <div class="col-50 clearfix haveToBox">
                    <!-- 结算日期  -->
                        <p class="tit"><spring:message code="purchaseContract_edit_contractEndDate"/></p>
                        <input type="text"  value="">
                        <p class="haveTo">*</p>
                    </div>
                </div>
            </div>
            <div class="w-330">
                <div class="items clearfix">     
                    <!-- 特殊说明  -->
                    <p class="tit"><spring:message code="purchaseContract_edit_specialExplain"/></p>
                    <textarea  style="width:220px;height: 70px">${purchaseContract.specialExplain }</textarea>
                </div>
            </div>
        </div>
        <div class="items clearfix">        	
            <div class="left w-65 clearfix">
           <!-- 合同条款 -->
                <p class="tit"><spring:message code="purchaseContract_edit_contractClause"/></p>
                <button type="button" onclick=""><spring:message code="quotation_create_select"/></button>
                </div>
                <div class="clearfix">
                <textarea  style="width:870px;height: 140px;">${purchaseContract.contractClause }</textarea>
            </div>
        </div>
        <div class="w-500 items clearfix">
            <div class="col-50 clearfix">
            <!-- 创建人员 -->
                <p class="tit"><spring:message code="purchaseContract_edit_creator"/></p>
                <input id="" name="" value="${purchaseContract.createBy.firstName }" >
            </div>
            <div class="col-50 clearfix">
            <!-- 创建时间 -->
                <p class="tit"><spring:message code="purchaseContract_edit_createDate"/></p>
                <input id="" name=""   value="<fmt:formatDate value="${purchaseContract.createDate }" pattern="yyyy-MM-dd" />" >
            </div>
        </div>
	</div>
    <div class="tabSm none">
    	<div class="tableArea">
        	<div class="tableScroll tableScrollSm">
        		<table cellpadding="0" class="tableHead">
                    <thead>
                    <tr>
                        <th><p class="tab-wltp"><spring:message code="purchaseContract_edit_materailImage"/></p></th>
                        <th><p class="width-150px"><spring:message code="purchaseContract_edit_materailNameNO"/></p></th>
                        <th><p class="width-70px"><spring:message code="purchaseContract_edit_materailSpec"/></p></th>
                        <th><p class="tab-dw"><spring:message code="purchaseContract_edit_materailSpecUnit"/></p></th>
                        <c:if test="${purchaseContract.purchaseType eq typeOfOrder }">
	                        <th><p class="tab-hjje"><spring:message code="purchaseContract_edit_supplierName"/></p></th>
	                        <th><p class="tab-dh"><spring:message code="purchaseContract_edit_contractNO"/></p></th>
	                        <th><p class="tab-sh"><spring:message code="purchaseContract_edit_reserveQuantity"/></p></th>
	                        <th><p class="tab-zdj"><spring:message code="purchaseContract_edit_realityQuantity"/></p></th>
                        </c:if>
                        <c:if test="${purchaseContract.purchaseType eq typeOfMtm }">
	                        <th><p class="width-160px"><spring:message code="purchaseContract_edit_customer"/></p></th>
		                    <th><p class="width-160px"><spring:message code="purchaseContract_edit_brand"/></p></th>
                        </c:if>
                        <c:if test="${purchaseContract.purchaseType eq purchaseType30 }">
	                        <th><p class="width-160px"><spring:message code="inventoryWarning_materialAlertQuantity"/></p></th>
		                    <th><p class="width-160px"><spring:message code="warningDate"/></p></th>
                        </c:if>
                        <th><p class="width-70px"><spring:message code="purchaseContract_edit_unitPrice"/></p></th>
                        <th><p class="width-70px"><spring:message code="purchaseContract_edit_quantity"/></p></th>
                        <th><p class="width-70px"><spring:message code="purchaseContract_edit_otherCost"/></p></th>
                        <th><p class="width-70px"><spring:message code="purchaseContract_edit_amount"/></p></th>
                    </tr>
                    </thead>
                </table>
                <table  cellpadding="0" class="tableBody" id="materialTable">
                    <tbody id="listHtml">
                    <c:forEach items="${purchaseContract.materialList }" var="material" varStatus="status">
                    <tr>
                        <td><p class="tab-wltp"><c:if test="${material.materialFile!=null && material.materialFile!='' }"><img src="${material.materialFile }" class="wltp"></c:if><c:if test="${material.materialFile==null||material.materialFile=='' }"><img src="${ctxStatic}/images/pic-none.jpg" class="wltp"></c:if></p></td>
                        <td><p class="width-150px">${material.materialCode }<br>${material.materialNameCN }</p></td>
                        <td><p class="width-70px">${material.materialSpec }</p></td>
                        <td><p class="tab-dw">${fns:getDictName(material.materialSpecUnitCD) }</p></td>
                        <input type="hidden" name="materialList[${status.index}].materialCode" value="${material.materialCode}"/>
                        <input type="hidden" name="materialList[${status.index}].materialNameCN" value="${material.materialNameCN}"/>
                        <input type="hidden" name="materialList[${status.index}].materialSpec" value="${material.materialSpec}"/>
                        <input type="hidden" name="materialList[${status.index}].materialSpecUnitCD" value="${fns:getDictName(material.materialSpecUnitCD) }"/>
                        <c:if test="${purchaseContract.purchaseType eq typeOfOrder }">
	                        <td><p class="tab-hjje">${material.ognizationNameB }</p></td>
	                        <td><p class="tab-dh">${material.contractNO }</p></td>
	                        <td><p class="tab-sh">${material.reserveQuantity }</p></td>
	                        <td><p class="tab-zdj">${material.realityQuantity }</p></td>
	                        <input type="hidden" name="materialList[${status.index}].ognizationNameB" value="${material.ognizationNameB}"/>
	                        <input type="hidden" name="materialList[${status.index}].contractNO" value="${material.contractNO}"/>
	                        <input type="hidden" name="materialList[${status.index}].reserveQuantity" value="${material.reserveQuantity}"/>
	                        <input type="hidden" name="materialList[${status.index}].realityQuantity" value="${material.realityQuantity}"/>
                        </c:if>
                        <c:if test="${purchaseContract.purchaseType eq typeOfMtm }">
	                        <td><p class="width-160px">${material.ognizationNameB }</p></td>
	                        <td><p class="width-160px">${material.brandName }</p></td>
	                        <input type="hidden" name="materialList[${status.index}].ognizationNameB" value="${material.ognizationNameB}"/>
	                        <input type="hidden" name="materialList[${status.index}].brandName" value="${material.brandName}"/>
                        </c:if>
                        <c:if test="${purchaseContract.purchaseType eq purchaseType30 }">
                            <td><p class="width-160px">${material.materialAlertQuantity }</p></td>
                            <td><p class="width-160px"></p></td>
                        </c:if>
                        <td><p class="width-70px"><fmt:formatNumber value="${material.purchaseUnitPrice }" pattern="#,##0.000##"/></p></td>
                        <td><p class="width-70px"><fmt:formatNumber value="${material.purchaseReserveQuantity }" pattern="#,##0.000##"/></p></td>
                        <td><p class="width-70px"><fmt:formatNumber value="${material.purchaseOtherCost }" pattern="#,##0.000##"/></p></td>
                        <td><p class="width-70px"><fmt:formatNumber value="${material.purchaseUnitPrice*material.purchaseReserveQuantity + material.purchaseOtherCost }" pattern="#,##0.000##"/></p></td>
                        <input type="hidden" name="materialList[${status.index}].purchaseUnitPrice" value="${material.purchaseUnitPrice }"/>
                        <input type="hidden" name="materialList[${status.index}].purchaseReserveQuantity" value="${material.purchaseReserveQuantity }"/>
                        <input type="hidden" name="materialList[${status.index}].purchaseOtherCost" value="${material.purchaseOtherCost }"/>
                        <input type="hidden" name="materialList[${status.index}].purchaseAllCost" value="${material.purchaseUnitPrice*material.purchaseReserveQuantity + material.purchaseOtherCost }"/>
                        <input type="hidden" name="materialID" value="${material.materialID}"/>
                    </tr>
                    </c:forEach>
                    </tbody>
                </table>
                
                <div id="hiddenHtml"></div>
            </div>
        </div>
    </div>
</div>
</form>
<script>
	window.onload = function(){
			var windowH = window.innerHeight
					||document.documentElement.clientHeight
					||document.body.clientHeight
			$('.tabSm').css({
				'height':windowH - 77,
			});
			$('.tableScrollSm').css({
				'height':windowH - 91
			})
		}
	$('.squareL').on('click', function() {
	    var lastCon = $('.square ol li:last-child').detach();
	    $('.square ol').prepend(lastCon)
	    $('.square ol li:last-child').addClass('active')
	    $('.square ol li:last-child').siblings().removeClass('active')
	})

	$('.squareR').on('click', function() {
	    var lastCon = $('.square ol li:first-child').detach();
	    $('.square ol').append(lastCon)
	    $('.square ol li:last-child').addClass('active')
	    $('.square ol li:last-child').siblings().removeClass('active')
	})
	$('.showHtml').find('input,select,textarea').attr('disabled','disabled');
</script>
</body>
</html>
